package priv.yiyuan.example.design.proxy;

import org.junit.Test;

public class ProxyDecoratorText {

    @Test
    public void test_proxyAndDecorator() {

        System.out.println("\n--- 场景1: 普通用户写入普通文件 ---");
        FileOperation normalUserFileOp = new FileAccessProxy("user1");
        normalUserFileOp.write("normal_file.txt", "这是一段普通文本内容。");
        String readContent1 = normalUserFileOp.read("normal_file.txt");
        System.out.println("最终读取内容: " + readContent1);

        System.out.println("\n--- 场景2: 普通用户尝试写入敏感文件 ---");
        normalUserFileOp.write("sensitive_data.txt", "这是敏感数据。");

        System.out.println("\n--- 场景3: 管理员写入加密的敏感文件 ---");
        FileOperation adminFileOp = new FileAccessProxy("admin");
        EncryptionDecorator encryptionAdminFileOp = new EncryptionDecorator(adminFileOp);
        encryptionAdminFileOp.write("sensitive_encrypted_file.txt", "这是一段需要加密的敏感信息。");
        String readContent2 = encryptionAdminFileOp.read("sensitive_encrypted_file.txt");
        System.out.println("最终读取内容: " + readContent2);

        System.out.println("\n--- 场景4: 管理员写入压缩并加密的大文件 ---");
        String largeContent = "这是一段非常非常长的大文本内容，需要进行压缩和加密处理，以节省存储空间并保证数据安全。";
        CompressionDecorator compressionEncryptedAdminFileOp = new CompressionDecorator(new EncryptionDecorator(adminFileOp));
        compressionEncryptedAdminFileOp.write("large_compressed_encrypted_file.txt", largeContent);
        String readContent3 = compressionEncryptedAdminFileOp.read("large_compressed_encrypted_file.txt");
        System.out.println("最终读取内容: " + readContent3);

    }

}
